package asmilk.astest.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import asmilk.astest.service.WeiboService;

@Controller
@RequestMapping("/weibo")
public class WeiboController {

	private static final Logger LOG = LoggerFactory.getLogger(WeiboController.class);

	@Autowired
	private WeiboService weiboService;

	@GetMapping(path = { "/authorize" })
	public String authorize(Model model, @RequestParam("code") String code) {
		LOG.info("code: {}", code);
		String content = this.weiboService.accessToken(code);
		model.addAttribute("content", content);
		return "weibo";
	}

}
